package com.sinoatma.physignsmonitor.bean


import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.sinoatma.physignsmonitor.MyApp

@Database(entities = [MonitorRecordEntity::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {

    // 获取 MonitorRecordDao
    abstract fun monitorRecordDao(): MonitorRecordDao

    companion object {
        @Volatile
        private var INSTANCE: AppDatabase? = null

        // 使用 MyApp.context 来获取上下文
        fun getDatabase(context: Context): AppDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context,  // 使用 MyApp 中的上下文
                    AppDatabase::class.java,
                    "monitor_records.db"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}
